using System.Collections.Generic;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
	public sealed class ResultFormatterTest
	{

		[TestFixture]
		public class GetErrorMessages
		{

			private const string expectedErrorMessage1 = "ErrorMessage1";
			private const string expectedErrorMessage2 = "Error\r\nMessage2";

			[Test]
			public void Simple()
			{
				var validationResults = new List<ValidationError>
				                                               {
				                                                   new ValidationError(new MockRule(), expectedErrorMessage1, null, null),
				                                                   new ValidationError(new MockRule(), expectedErrorMessage2, null, null)
				                                               };
			    var messages = ResultFormatter.GetErrorMessages(validationResults);
				Assert.AreEqual(expectedErrorMessage1, messages[0]);
				Assert.AreEqual(expectedErrorMessage2, messages[1]);
			}
			[Test]
			public void SplitOnNewLine()
			{
				var validationResults = new List<ValidationError>
				                                               {
				                                                   new ValidationError(new MockRule(), expectedErrorMessage1, null, null),
				                                                   new ValidationError(new MockRule(), expectedErrorMessage2, null, null)
				                                               };
			    var messages = ResultFormatter.GetErrorMessages(validationResults, true);
				Assert.AreEqual(expectedErrorMessage1, messages[0]);
				Assert.AreEqual("Error", messages[1]);
				Assert.AreEqual("Message2", messages[2]);
			}
		}


		[TestFixture]
		public class GetConcatenatedErrorMessages
		{

			private const string expectedErrorMessage1 = "ErrorMessage1";
			private const string expectedErrorMessage2 = "ErrorMessage2";

			[Test]
			public void Simple()
			{
				var validationResults = new List<ValidationError> 
				{
					new ValidationError(new MockRule(), expectedErrorMessage1, null, null), 
					new ValidationError(new MockRule(), expectedErrorMessage2, null, null)
				};

				var concatenatedErrorMessages = ResultFormatter.GetConcatenatedErrorMessages(validationResults);
				Assert.AreEqual("ErrorMessage1\r\nErrorMessage2", concatenatedErrorMessages);
			}
			[Test]
			public void StringCollection()
			{
				var validationResults = new List<string> {expectedErrorMessage1, expectedErrorMessage2};

			    var concatenatedErrorMessages = ResultFormatter.GetConcatenatedErrorMessages(validationResults);
				Assert.AreEqual("ErrorMessage1\r\nErrorMessage2", concatenatedErrorMessages);
			}
			[Test]
			public void SimpleSeperator()
			{
				var validationResults = new List<ValidationError>
				                                               {
				                                                   new ValidationError(new MockRule(), expectedErrorMessage1, null, null),
				                                                   new ValidationError(new MockRule(), expectedErrorMessage2, null, null)
				                                               };

			    var concatenatedErrorMessages = ResultFormatter.GetConcatenatedErrorMessages(",",validationResults);
				Assert.AreEqual("ErrorMessage1,ErrorMessage2", concatenatedErrorMessages);
			}
			[Test]
			public void StringCollectionSeperator()
			{
				var validationResults = new List<string> {expectedErrorMessage1, expectedErrorMessage2};

			    var concatenatedErrorMessages = ResultFormatter.GetConcatenatedErrorMessages(",",validationResults);
				Assert.AreEqual("ErrorMessage1,ErrorMessage2", concatenatedErrorMessages);
			}
		}

	}
}